<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/change-phone.css">
<style type="text/css">
.footer{
    display: none;
}
</style>
</block>
<block name="main">
    <div class="form">
        <div class="form-group">
            <div class="left">
                <span>手机号码</span>
            </div>
            <div class="right">
                <span>{:hidtel($user['user_phone'])}</span>
            </div>
        </div>
        <div class="form-group">
            <input type="text" name="code"  class="phone-text" placeholder="请输入验证码">
            <div class="phone-text-wrapper">
                <button class="get-verify-code" onclick="getcode()">获取验证码</button>
            </div>
        </div>
    </div>
    <div class="btn-wrapper">
        <a herf="javascript:" onclick="sub()">下一步</a>
    </div>
</block>
 <block name="js">
 <script type="text/javascript">
        function getcode(){
            event_send_sms()
         
        }

          //验证码计时
        var timer = 60;
        function codeTimer()
        {
            timer--;
            if(timer > 0){
                $('.get-verify-code').text( timer + '秒后可重发!');
                $('.get-verify-code').attr("send",1);
                setTimeout('codeTimer()', 1000);
            }else{
                $('.get-verify-code').text('获取验证码');
                $('.get-verify-code').attr("send",0);
                timer = 60;
            }
        }

    //发送短信
    function event_send_sms(){
        var phone = "{$user['user_phone']}";
        var postData={
            role:3,
            phone:phone,
            val:1
        }
        if(timer >= 60){
                $(this).attr('disabled', 'disabled');
                $.ajax({
                    url:'/Home/Sms/change_phone_sms',
                    data:postData,
                    type:"post",
                    dataType:"json",
                    success:function(d){
                        if(d.err == 0){
                            codeTimer();
                        }else{
                            layer.open({
                                content:d.msg
                                ,skin: 'msg'
                                ,time: 1 //2秒后自动关闭
                            });
                        }
                    }
                });
            
        } 
    }

    function sub(){
        var code=$('input[name="code"]').val();
        console.log(code)
        $.post('{:U("Person/change_phone")}',{
            code:code,
        },function(res){
           if(res.err==0){
            location.href="/Home/Person/change_phone_end"
           }else{
               layer.open({
                    content:res.msg
                    ,skin: 'msg'
                    ,time: 1 //2秒后自动关闭
                });

           }
        })
    }
 </script>
 </block>